define(['../counter.js'],
    (Counter) => {
    class Weapon {
        constructor(launcher) {
            this.pressing = false
            this.bullets = []
            this.booms = []
            this.types = ['bullet', 'laser']
            this.type = 'laser'
            this.launcher = launcher
            this.cooldown = new Counter(0)
            this.type_counter = new Counter(this.types.length)
            this.switch_callback = []


            this.switch_by_name('laser')
        }
        switch_by_name(name) {
            if (this.types.find(t => t == name) == null) {
                const text = 'You can not switch a invalid weapon called:' + name
                console.error(text)
                // this.log(text)
                return
            }

            this.type = name

            // Update the type counter
            for (let i = 0; i < this.types.length; i++) {
                if (this.types[i] == name) {
                    this.type_counter.set(i)
                    break
                }
            }
        }
        switch() { // switch in turn
            this.type_counter.update()
            if (this.type_counter.is_over()) {
                this.type_counter.reset()
            }
            this.type = this.types[this.type_counter.get()]
        }
        cooldown_update() {
            this.cooldown.update()
        }
        is_cooldown_over() {
            return this.cooldown.is_over()
        }
    }

    return Weapon
})